#include <math.h>
#include <iostream>
#include <SDL/SDL.h>
#include <SDL_image.h>
#include "gamestate.h"
#include "gameengine.h"
#include "introstate.h"
#include "menustate.h"
#include "playstate.h"

CMenuState menuState;
extern CIntroState introState;
extern CPlayState playState;

void CMenuState::Init()
{
    menu = IMG_Load("menu.png");
//    if(!menu)
    {
//        exit(123);
    }
//    mx = 0;
//    my = 1;
    dstrect.x = 0;
    dstrect.y = 0;
    dstrect.h = menu->h;
    dstrect.w = menu->w;


}

void CMenuState::Cleanup()
{
    //printf("Cleanup\n");
    SDL_FreeSurface(menu);
    SDL_ShowCursor(false);
}

void CMenuState::Pause()
{
}

void CMenuState::Resume()
{
}

void CMenuState::HandleEvents(CGameEngine* game)
{
    SDL_Event event;
    //printf("start event\n");
    if (SDL_PollEvent(&event))
    {
        switch (event.type)
        {
        case SDL_QUIT:
//            game->Quit();
            break;

        case SDL_KEYDOWN:
            switch (event.key.keysym.sym)
            {
            case SDLK_SPACE:
               game->PopState();
                break;
            case SDLK_UP:
                break;
            case SDLK_DOWN:
                break;
            case SDLK_LEFT:
                break;
            case SDLK_RIGHT:
                break;

            }
            break;

        case SDL_KEYUP:
            switch (event.key.keysym.sym)
            {
            case SDLK_UP:
                ppx+=1;
                break;
            case SDLK_DOWN:
                break;
            case SDLK_LEFT:
                break;
            case SDLK_RIGHT:
                break;
            }
            break;

        case SDL_MOUSEMOTION:
            break;
        case SDL_MOUSEBUTTONDOWN:
            switch(event.button.button)
            {
            case SDL_BUTTON_WHEELUP:
                break;
            case SDL_BUTTON_WHEELDOWN:
                break;
            }

        }
    }
    //printf("end event\n");
}

void CMenuState::Update(CGameEngine* game)
{
//    printf("Update\n");
}

void CMenuState::Draw(CGameEngine* game)
{

    //printf("Draw %s\n", SDL_GetError());
    if(dstrect.x+X<10*X)
        dstrect.x+=3;
    else
        dstrect.x=-X;
    SDL_BlitSurface(menu, NULL, game->screen, &dstrect);
}
